package torres.action;

import java.util.Collection;

import torres.controller.Direction;
import torres.entity.Entity;
import torres.map.Location;
import torres.map.World;

/**
 * @author Torres
 * Actions with a linear influence radius
 */
public class LinearAction extends Action {

	private Direction direction;
	
	/**
	 * Creates a new LinearAction
	 * @param elem Elemental type of AngularAction
	 * @param range range of AngularAction
	 * @param direction direction of AngularAction
	 * @param power power damage of AngularAction
	 * @param accuracy accuracy of AngularAction
	 * @param delay Time delay of consecutive AngularAction 
	 */
	public LinearAction(Effect elem, int range, int power, int accuracy, int delay) {
		super(elem, range, power, accuracy, delay);
	}
	
	/**
	 * Creates a new LinearAction
	 * @param elem Elemental type of AngularAction
	 * @param range range of AngularAction
	 * @param direction direction of AngularAction
	 * @param location location of AngularAction
	 * @param power power damage of AngularAction
	 * @param accuracy accuracy of AngularAction
	 * @param delay Time delay of consecutive AngularAction 
	 */
	public LinearAction(Effect elem, int range, Direction direction, Location location, int power, int accuracy, int delay) {
		super(elem, range, location, power, accuracy, delay);
		this.setDirection(direction);
		
	}

	/**
	 * Sets the direction of AngularAction
	 * @param direction the new direction to set
	 */
	private void setDirection(Direction direction) {
		this.direction = direction;
	}

	/**
	 * Returns the direction of AngularAction
	 * @return the direction
	 */
	protected Direction getDirection() {
		return direction;
	}
	
	/**
	 * Returns a collection of Locations
	 * @return Collection of Locations
	 * @see torres.action.Action#getLocations()
	 */
	protected Collection<Collection<Location>> getLocations() {
		return Location.linearCollection(this.getLocation(), this.getDirection(), this.getRange());
	}
	
	/**
	 * Sets up the origin of LinearAction 
	 * @param e new Entity used as reference to set
	 */
	public void setUp(Entity e) {
		this.setMap(World.getInstance().getCurrentMap());
		this.setLocation(Location.locationInDirection(e.getLocation(), e.getDirection()));
		this.setDirection(e.getDirection());
		double multiplier = e.getOccupation().applySkill(this.getElement());
		this.setPower((int)(this.getPower() * multiplier));
		this.setAccuracy((int)(this.getAccuracy() * multiplier));
	}
}
